package springapp.validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import springapp.service.UserRegistrationForm;

@Component("registrationValidator")
public class UserRegistrationValidator implements Validator {

	@Override
	public boolean supports(Class aClass) {
		return UserRegistrationForm.class.equals(aClass);
	}

	@Override
	public void validate(Object arg0, Errors errors) {
		UserRegistrationForm form = (UserRegistrationForm)arg0;
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required", "Required field");	
	}

}
